package com.bops.dal.product.dao.impl;

import java.util.List;

import com.bops.dal.product.dao.SupplierDAO;
import com.bops.dal.product.dataobject.SupplierDO;
import com.bops.dal.product.queryobject.SupplierQuery;
import com.yue.commons.db.ibatis.YueBaseSqlMapClientDaoSupport;

public class SupplierDAOImpl  extends YueBaseSqlMapClientDaoSupport implements SupplierDAO{

	private static final String NAME_SPACE = "SUPPLIER_INFO.";
	
	public Integer insert(SupplierDO supplierDO) {
		 return (Integer) getSqlMapClientTemplate().insert(NAME_SPACE + "insert", supplierDO);
	}

	public boolean update(SupplierDO supplierDO) {
		return getSqlMapClientTemplate().update(NAME_SPACE + "update", supplierDO) > 0;
	}

	public SupplierDO getById(Integer id) {
		return (SupplierDO) getSqlMapClientTemplate().queryForObject(NAME_SPACE + "listById", id);
	}

    @SuppressWarnings("unchecked")
	public List<SupplierDO> listSupplier(SupplierQuery query) {
    	if (query==null)
        {
            query = new SupplierQuery();
            query.setPageSize(Integer.MAX_VALUE);
        }
		return getSqlMapClientTemplate().queryForPagination(NAME_SPACE + "count_supplier", NAME_SPACE + "list_supplier", query);
	}

	public boolean delete(Integer id) {
		return getSqlMapClientTemplate().delete(NAME_SPACE + "delete", id) > 0;
	}

	public int checkSupplier(SupplierDO editSupplier) {
		return (Integer) getSqlMapClientTemplate().queryForObject(NAME_SPACE + "checkName",  editSupplier);
	}

}
